package com.sx.zongzhi.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.activity.ImagePlayActivity;
import com.sx.zongzhi.bean.EconomicOrganizionBean;
import com.sx.zongzhi.net.ServiceFactory;
import com.sx.zongzhi.utils.BaseUtil;

import java.io.File;
import java.util.List;

/**非公有制经济组织
 * Created by admin on 2017/12/8.
 */

public class EconomicOrganizationAdapter extends BaseQuickAdapter<EconomicOrganizionBean,BaseViewHolder> {

    private Context context;

    public EconomicOrganizationAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<EconomicOrganizionBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, EconomicOrganizionBean item) {
        helper.setText(R.id.tv_Title, BaseUtil.isEmpty(item.getName()) ? "" : item.getName());
        helper.setText(R.id.tv_type, item.getStyle() == null ? "" : item.getStyle().getDisplayName());
        helper.setText(R.id.tv_address, BaseUtil.isEmpty(item.getResidence()) ? "" : item.getResidence());
        helper.setText(R.id.tv_isDangerousEnterprise, item.isDangerousEnterprise() ? "是否危化企业(是)" : "是否危化企业(否)");
        ImageView imageView = helper.getView(R.id.imv_picture);
        if (!BaseUtil.isEmpty(item.getImgUrl())){
            final String path=ServiceFactory.NEW_API_BASE_URL+ File.separator + item.getImgUrl();
            RequestOptions options = new RequestOptions().centerCrop()
                    .placeholder(R.mipmap.img_enterprise)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .error(R.mipmap.img_enterprise);
            Glide.with(mContext)
                    .load(path)
                    .apply(options)
                    .into(imageView);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(new Intent(context, ImagePlayActivity.class)
                    .putExtra("path",path));
                }
            });
        }
    }
}
